<script setup>
import { onMounted, ref, onBeforeUnmount } from "vue"
import { household, important, reset_params } from "@/js/request_params"
import { get_json_object } from "@/js/area"
import { gender, bloodMap, nation, education, marry, military, persontype, undercontrol } from "@/js/base_info_map";
import zhCn from "element-plus/es/locale/lang/zh-cn"
import { Object } from "core-js";
import { select_by_idNum } from "@/api/impPop";
import { final_fail } from "@/api/impPop";
import { final_pass } from "@/api/impPop";
import { userStore } from "@/store/user";
import { select_imp_idnum_info } from '@/js/resident_request_func';
import { ElMessage } from "element-plus";
import { select_audit_imp_info } from "@/api/impPop"
// 后续扩展请复制该文件
//family_establishment_服务
let json_object = ref([]);
const locale = ref(zhCn);
const service_form = ref();
const store = userStore();
const direction = ref('btt');
const drawer = ref(false);
const handle_select = (row_params) => {
  let keys = Object.keys(row_params)
  keys.forEach((key) => {
    important.value[key] = row_params[key]
  })
}
const query_response = ref([
  {
    persontype: "111",
    personnum: '1',
    pid: '派出所',
    undercontrol: '未控',
    name: '耳春龙',
    gender: '男',
    birthday: '111',
    nation: '汉族',
    idnum: '111'
  }
]);
const disabledDate = (time) => {
  return time.getTime() > Date.now();
}
const handle_close = () => {
  drawer.value = false;
}
const initImportant = () => {
  important.value.pid = store.get_use_info.pid;
  important.value.operatorId = store.get_use_info.id;
  important.value.changetype = "重点人口信息审批";
  important.value.changereson = "重点人口信息审批";
  important.value.pname = store.get_use_info.pname;
  important.value.popTypeId = 2;
}

const resteImportant = () => {

  important.value.name = '';
  important.value.idnum = '';
  important.value.birthday = '';
  important.value.genderId = '';
  important.value.nationId = '';
  important.value.bloodId = '';
  important.value.eduId = '';
  important.value.marryId = '';
  important.value.disabilityId = '';
  important.value.militaryId = '';
  important.value.address = '';
  important.value.persontypeId = '';
  important.value.undercontrolId = '';
  important.value.personnum = '';
  // initImportant();
}


onMounted(async () => {
  let response = await get_json_object()
  json_object.value.push(response);
  initImportant()
})
const finalfail = () => {
  final_fail(important.value).then((res) => {
    ElMessage.success(res.msg);
    resteImportant();
  })
}
const finalpass = () => {
  final_pass(important.value).then((res) => {
    ElMessage.success(res.msg);
    resteImportant();
  })
}
const selectAllImpInfo = () => {
  drawer.value = true
  select_audit_imp_info({ 'option': 3 }).then((res) => {
    console.log(res.result);
    query_response.value = res.result;
    query_response.value.forEach((imp) => {
      imp.persontype = persontype.value[imp.persontypeId];
      imp.undercontrol = undercontrol.value[imp.undercontrolId];
      imp.gender = gender.value[imp.genderId];
      imp.nation = nation.value[imp.nationId];
    })

    console.log(query_response.value);

  })

}

onBeforeUnmount(() => {
  reset_params(important.value)
}) 
</script>
<template>
  <!-- 表单 -->
  <el-drawer v-model="drawer" title="查询结果" :direction="direction" :before-close="handle_close">
    <template #default>
      <div class="w-[100%] h-[100%] flex justify-center">
        <el-table :data="query_response" stripe style="width: 100%">
          <el-table-column prop="persontype" label="人员类型" width="220" />
          <el-table-column prop="personnum" label="人员编号" width="220" />
          <el-table-column prop="undercontrol" label="在控状态" width="220" />
          <el-table-column prop="name" label="姓名" width="220" />
          <el-table-column prop="gender" label="性别" width="220" />
          <el-table-column prop="birthday" label="出生日期" width="220" />
          <el-table-column prop="nation" label="民族" width="220" />
          <el-table-column prop="idnum" label="证号" />
          <el-table-column fixed="right" label="操作">
            <template #default="scope">
              <el-button link type="primary" size="default" @click="handle_select(scope.row)">
                选择
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </template>
  </el-drawer>
  <div class="w-[100%] h-[100%] flex justify-center">
    <div class="card w-[100%] h-[100%] flex justify-center">
      <spa class="span"></spa>
      <span class="span"></span>
      <span class="span"></span>
      <spa class="span"></spa>
      <div class="shell shadow-xl" style="width:90%;height:90%">
        <svg class="check" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">

          <path
            d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM369 209L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9z">
          </path>
        </svg>
        <p class="tracking-[10px] text-[20px] font-[800] text-black">重点人口信息审批</p>
        <el-form class="grid  grid-cols-3 gap-x-14 -gap-y-1  relative justify-items-center items-center"
          :model="important" ref="service_form" :rules="rules">
          <el-form-item label="姓名:">
            <el-input v-model="important.name" placeholder="请填写内容" disabled></el-input>
          </el-form-item>
          <el-form-item label="性别:">
            <el-select v-model="important.genderId" placeholder="">
              <el-option v-for="index in Object.keys(gender).length" :key="index" :label="gender[index]"
                :value="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="人员类别:">
            <el-select v-model="important.persontypeId" placeholder="请选择" disabled>
              <el-option v-for="index in Object.keys(persontype).length" :key="index" :label="persontype[index]"
                :value="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="出生日期:">
            <el-config-provider :locale="locale">
              <el-date-picker style="width:180px" v-model="important.birthday" format="YYYY-MM-DD"
                value-format="YYYY-MM-DD" type="date" placeholder="请选择" :disabled-date="disabledDate"
                :size="'default'" />
            </el-config-provider>
          </el-form-item>
          <el-form-item label="身份证号:">
            <el-input v-model="important.idnum" placeholder="请填写内容" @change="select_imp_idnum_info"></el-input>
          </el-form-item>
          <el-form-item label="婚姻状况:">
            <el-select v-model="important.marryId" placeholder="请选择" disabled>
              <el-option v-for="index in Object.keys(marry).length" :key="index" :label="marry[index]"
                :value="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="在控状态:">
            <el-select v-model="important.undercontrolId" placeholder="请选择" disabled>
              <el-option v-for="index in Object.keys(undercontrol).length" :key="index" :label="undercontrol[index]"
                :value="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="人员编号:">
            <el-input v-model="important.personnum" placeholder="请填写内容" disabled></el-input>
          </el-form-item>
          <el-form-item label="户籍地址:">
            <el-input v-model="important.address" placeholder="请填写内容" disabled></el-input>
          </el-form-item>
          <el-form-item label="血型:">
            <el-select v-model="important.bloodId" placeholder="" disabled>
              <el-option v-for="index in Object.keys(bloodMap).length" :key="index" :label="bloodMap[index]"
                :value="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="民族:">
            <el-select v-model="important.nationId" placeholder="请选择" disabled>
              <el-option v-for="index in Object.keys(nation).length" :key="index" :label="nation[index]"
                :value="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="文化程度:">
            <el-select v-model="important.eduId" placeholder="请选择" disabled>
              <el-option v-for="index in Object.keys(education).length" :key="index" :label="education[index]"
                :value="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="兵役状况:">
            <el-select v-model="important.militaryId" placeholder="请选择" disabled>
              <el-option v-for="index in Object.keys(military).length" :key="index" :label="military[index]"
                :value="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类别:">
            <el-input placeholder="重点人口信息采集" disabled></el-input>
          </el-form-item>
          <el-form-item label="派出所:">
            <el-input v-model="important.pname" placeholder="请填写" disabled></el-input>
          </el-form-item>
        </el-form>

        <hr>
        <div class="relative -top-1  flex justify-around items-center">
          <button class="card_button" @click="finalpass">
            通过
            <svg class="arrow" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
              <path
                d="M470.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 256 265.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160zm-352 160l160-160c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L210.7 256 73.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z">
              </path>
            </svg>
          </button>
          <button class="card_button" @click="selectAllImpInfo">
            查询重点人口
            <svg class="arrow" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
              <path
                d="M470.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 256 265.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160zm-352 160l160-160c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L210.7 256 73.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z">
              </path>
            </svg>
          </button>
          <button class="card_button" @click="finalfail">
            不通过
            <svg class="arrow" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
              <path
                d="M470.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 256 265.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160zm-352 160l160-160c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L210.7 256 73.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z">
              </path>
            </svg>
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
@import url(../css/form_card.css);

.el-form {
  height: 70%;
}

:deep(.el-input__wrapper:hover) {
  --tw-ring-color: rgb(233 213 255);
  box-shadow: var(--tw-ring-inset) 0 0 3px calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
  scale: 1.03;
}

:deep(.el-input__wrapper) {
  transition: all 500ms;
}

.el-input :deep(.el-input__wrapper.is-focus) {
  --tw-ring-color: rgb(216 180 254);
  --tw-ring-offset-color: #84f2fc;
  box-shadow: var(--tw-ring-inset) 0 0 3px calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);

}

.el-input :deep(.el-input__wrapper) {
  transition: all 500ms;
}

.el-input,
.el-select {

  width: 180px;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

:deep(.el-form-item__label) {
  text-shadow: 1px 2px 2px rgba(165, 165, 165, 0.8);
}

.el-form-item:nth-child(1) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 12px;
}

.el-form-item:nth-child(2) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 12px;
}

.el-form-item:nth-child(3) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(4) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(5) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(6) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(7) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(8) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(9) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(10) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 12px;
}

.el-form-item:nth-child(11) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 12px;
}

.el-form-item:nth-child(12) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(13) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(14) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(15) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 6px;
}

.el-form-item:nth-child(16) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(17) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 2px;
}

.el-form-item:nth-child(18) :deep(.el-form-item__label) {
  position: relative;
  right: 0;
  letter-spacing: 1px;
}
</style>
